//
//  ListColumn.swift
//  Sorts
//
//  Created by lhc on 2023/12/8.
//

import SwiftUI



struct ListColumn: View {
    
    @State var vm = ViewModel()
    
    var body: some View {
        VStack {
            HStack(alignment: .bottom, spacing: 10) {
                ForEach(vm.dataArray) {data in
                    Histogram(num: data.num)
                }
            }
            .frame(width: 700)
            .padding(.vertical, 100)
            
            VStack(alignment: .leading, spacing: 20) {
                HStack(spacing: 30) {
                    Button {
                        withAnimation {
                            vm.selectSortClick()
                        }
                        
                    } label: {
                        Text("选择排序")
                            .font(.body)
                            .padding()
                    }
                    
                    
                    Button {
                        withAnimation {
                            vm.insertSortClick()
                        }
                        
                    } label: {
                        Text("赋值插入排序")
                            .font(.body)
                            .padding()
                    }
                    
                    Button {
                        withAnimation {
                            vm.insertExchangeSortClick()
                        }
                    } label: {
                        Text("交换插入排序")
                            .font(.body)
                            .padding()
                    }
                    
                    Button {
                        withAnimation {
                            vm.bubbleSortClick()
                        }
                    } label: {
                        Text("冒泡排序")
                            .font(.body)
                            .padding()
                    }
                    
                    Button {
                        withAnimation {
                            vm.mergeSortClick()
                        }
                    } label: {
                        Text("归并排序")
                            .font(.body)
                            .padding()
                    }
                    
                    
                }
                HStack(spacing: 30) {
                    Button {
                        withAnimation {
                            vm.quickSortOneWaysClick()
                        }
                    } label: {
                        Text("单路快速排序")
                            .font(.body)
                            .padding()
                    }
                    
                    Button {
                        withAnimation {
                            vm.quickSortTwoWaysClick()
                        }
                    } label: {
                        Text("双路快速排序")
                            .font(.body)
                            .padding()
                    }
                    
                    Button {
                        withAnimation {
                            vm.quickSortThreeWaysClick()
                        }
                    } label: {
                        Text("三路快速排序")
                            .font(.body)
                            .padding()
                    }
                }
            }
            .padding()
        }
        .padding(.vertical)
    }
}

#Preview {
    ListColumn()
}
